Ext.define('Admin.view.system.vote.OptionController', {

	extend : 'Admin.ux.GridController',

	alias : 'controller.option',
	
	//增加选项
	addOptionAction:function(b){
		var me = this;
		var win = Ext.create("Admin.ux.Window", {
			title : '创建投票选项',
			animateTarget : b,
			width : '30%',
			height : '35%',
			items : {
				xtype : 'option-displayform'
			},
			buttons : [
					{
						text : '保存',
						ui : 'soft-green',
						iconCls : 'x-fa 	fa-floppy-o',
						handler : function(btn) {
							var form = btn.up("window").down("form").getForm();
							Ext.create('Admin.ux.Action').submit(form,
									'/vote/addOption', me.getView(), win);
						}
					}, {
						text : '重置',
						ui : 'soft-red',
						iconCls : 'x-fa 	fa-mail-reply',
						handler : function(btn) {
							btn.up("window").down("form").reset();
						}
					}, {
						text : '取消',
						ui : 'gray',
						iconCls : 'x-fa 	fa-ban',
						handler : function(btn) {
							btn.up("window").close();
						}
					} ]
		});
	},
	//编辑选项
	editOptionAction : function(grid, rowIndex, colIndex, item, e, record, row) {

		var rec = grid.getStore().getAt(rowIndex);
		var me = this;
		var win = Ext.create("Admin.ux.Window", {
			title : '编辑投票选项',
			animateTarget : row,
			width :  '30%',
			height : '35%',
			items : {
				xtype : 'option-displayform'
			},
			buttons : [
					{
						text : '保存',
						ui : 'soft-green',
						iconCls : 'x-fa 	fa-floppy-o',
						handler : function(btn) {
							var form = btn.up("window").down("form").getForm();
							Ext.create('Admin.ux.Action').submit(form,
									'/vote/editOption', me.getView(), win);
						}
					}, {
						text : '重置',
						ui : 'soft-red',
						iconCls : 'x-fa 	fa-mail-reply',
						handler : function(btn) {
							var form = btn.up("window").down("form");
							form.loadRecord(rec);
						}
					}, {
						text : '取消',
						ui : 'gray',
						iconCls : 'x-fa 	fa-ban',
						handler : function(btn) {
							btn.up("window").close();
						}
					}

			],
			listeners : {
				show : function(w, opts) {
					var form = this.down('form');
					form.getForm().load({
						url : '/vote/getOption',
						waitMsg : '加载中...',
						params : {
							id : rec.get('id')
						},
					});
				}
			}
		});

	},
	//删除选项
	removeOptionAction : function(grid, rowIndex, colIndex, item, e, record, row) {
		var rec = grid.getStore().getAt(rowIndex);
		var _id = rec.data.id;
		Ext.create('Admin.ux.Action').remove({
			id : _id
		}, '/vote/delOption', this.getView(), row);
	},
});
